package com.three.service;

import java.util.ArrayList;
import java.util.List;

import com.three.DAO.impl.ConsumInfoDAOImpl;
import com.three.DAO.impl.MobileCardDAOImpl;
import com.three.entity.ConsumInfo;
import com.three.entity.MobileCard;

public class chargeMoney {
	double sum;
	int talk;
	int sms;
	int flow;
	double money;
	ConsumInfoDAOImpl cidi=new ConsumInfoDAOImpl();
	MobileCard mobilecard=new MobileCard();
	MobileCardDAOImpl mcdi=new MobileCardDAOImpl();
	public void chargeMoney(MobileCard mobilecard) {
	cidi.getConsumInfoByNum(mobilecard);
	 List<ConsumInfo> list=cidi.getConsumInfoByNum(mobilecard);
	for(int i=0;i<list.size();i++) {
	  sum=list.get(i-1).getPrice();
	  talk=list.get(i-1).getTalkTime();
	  sms=list.get(i-1).getSmsCount();
	  flow=list.get(i-1).getFlow();
			
	}
	mcdi.selectMobileCard(mobilecard);
	money=mobilecard.getMoney()-mobilecard.getServicePackage().getPrice()-sum;
	mobilecard.setConsumAmount(sum);
	mobilecard.setRealFlow(flow);
	mobilecard.setRealSMSCount(sms);
	mobilecard.setRealTalkTime(talk);
	mobilecard.setMoney(money);
	mcdi.updateMobileCard(mobilecard);
	}

}
